/*	SM.h
 *
 *	This is an C include file that defines the public
 *	interface of the Apple Sound Manager.
 *
 *	Copyright © Apple Computer, Inc. 1986, 1987
 *	All Rights Reserved.
 *
 */
 
#ifndef __SoundManager__
#define __SoundManager__

#include <types.h>


/* Error codes */
#define noErr				0
#define noHardware			-200
#define notEnoughHardware	-201
#define queueFull			-203
#define resProblem			-204
#define badChannel			-205
#define badFormat			-206

#define SynthCodeRsrc		'snth'
#define SoundListRsrc		'snd '

#define NoteSynth			2
#define WaveTableSynth		3
#define MIDISynth			4
#define SampledSynth		5


#define TwelthRootTwo		1.05946309434
typedef	long				Time;				/* in half milliseconds */
#define InfiniteTime		0x7FFFFFFF



typedef struct SndCommand
{
	unsigned short			commandNum;
	short					wordArg;
	long					longArg;
}
	SndCommand;

#define NullCmd				0
#define InitCmd				1
#define FreeCmd				2
#define QuietCmd			3
#define FlushCmd			4

#define WaitCmd				10
#define PauseCmd			11
#define ResumeCmd			12
#define CallBackCmd			13
#define SyncCmd				14
#define EmptyCmd			15

#define TickleCmd			20
#define RequestNextCmd		21
#define HowOftenCmd			22
#define WakeUpCmd			23
#define AvailableCmd		24

#define ScaleCmd			30
#define TempoCmd			31

#define NoteCmd				40
#define RestCmd				41
#define FreqCmd				42
#define AmpCmd				43
#define TimbreCmd			44

#define WaveTableCmd		60
#define PhaseCmd			61

#define SoundCmd			80
#define BufferCmd			81
#define RateCmd				82

#define DataPointerFlag		0x8000

typedef struct ModifierStub
{
	struct ModifierStub		*next;
	ProcPtr					modifierCode;
	long					userInfo;
	Time					count,
							every;
	char					flags;
	char					hState;
}
	ModifierStub, *ModifierStubPtr;



#define StdQLength			128

typedef struct SndChannel
{
	struct SndChannel		*next;
	ModifierStubPtr			modifierChain;
	ProcPtr					callBack;
	long					userInfo;
	
	/* The following is for internal Sound Manager use only. */
	Time					wait;
	SndCommand				cmdInProgress;
	short					flags;
	short					qLength,
							qHead,		/* next spot to read or -1 if empty */
							qTail;		/* next spot to write, = qHead if full */
	SndCommand				queue[StdQLength];
}
	SndChannel, *SndChannelPtr;



/* Standard Synthesizer Structures */

/* Sampled Sound Synthesizer */

typedef struct SoundHeader
{
	char				* samplePtr;	/* if NIL then samples are in sampleArea */
	unsigned long		length;
	Fixed				sampleRate;
	unsigned long		loopStart,
						loopEnd;
	short				baseNote;
	char				sampleArea[0];
} SoundHeader, *SoundHeaderPtr;


/* Wave Table Synthesizer <C??? 13jan87 mgl>*/

#define WaveInitChannelMask		0x07
#define WaveInitChannelLeft		0x02
#define WaveInitChannelRight	0x03
#define WaveInitChannel0		0x04
#define WaveInitChannel1		0x05
#define WaveInitChannel2		0x06
#define WaveInitChannel3		0x07
#define WaveInitSRateMask		0x30
#define WaveInitSRate22k		0x20
#define WaveInitSRate44k		0x30
#define WaveInitStereoMask		0xC0
#define WaveInitStereoMono		0x80
#define WaveInitStereoStereo	0xC0



/* Sound List Resource Format */

/* the zero array sizes are here mearly to get this through the compilier */

typedef struct SndListResource
{
	short				format;
	short				numModifiers;
	struct modRef {
		unsigned short	modNumber;
		long			modInit;
	}					modifierPart[0];
	short				numCommands;
	SndCommand			commandPart[0];
	char				dataPart[0];
} SndListResource, *SndListPtr;

#define FirstSoundFormat	0x0001		/* first and only version we can deal with */


#ifndef __SoundManagerTraps__
#define __SoundManagerTraps__

/* User callable routines */
pascal OSErr SndDoCommand(chan, cmd, noWait)
	SndChannelPtr		chan;
	SndCommand			* cmd;
	Boolean				noWait;
extern 0xA803;

pascal OSErr SndDoImmediate(chan, cmd)
	SndChannelPtr		chan;
	SndCommand			* cmd;
extern 0xA804;

pascal OSErr SndAddModifier(chan, modifierCode, id, init)
	SndChannelPtr		chan;
	ProcPtr				modifierCode;
	short				id;
	long				init;
extern 0xA802;

pascal OSErr SndNewChannel(chanVar, synth, init, userRoutine)
	SndChannelPtr		* chanVar;
	short				synth;
	long				init;
	ProcPtr				userRoutine;
extern 0xA807;

pascal OSErr SndDisposeChannel(chan, quietNow)
	SndChannelPtr		chan;
	Boolean				quietNow;
extern 0xA801;

pascal OSErr SndPlay(chan, sList, async)
	SndChannelPtr		chan;
	Handle				sList;
	Boolean				async;
extern 0xA805;

pascal OSErr SndControl(id, cmdVar)
	short				id;
	SndCommand			* cmdVar;
extern 0xA806;

#endif

#endif